<!--
 * @Description: 事件冒泡
 * @Author: rendc
 * @Date: 2021-09-07 09:58:35
 * @LastEditors: rendc
 * @LastEditTime: 2021-09-07 10:11:47
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件冒泡</title>
  <style>
    .outer {
      border: 1px solid yellowgreen;
      width: 300px;
      height: 300px;
    }

    .center {
      border: 1px solid yellowgreen;
      width: 200px;
      height: 200px;
    }

    .inner {
      border: 1px solid yellowgreen;
      width: 100px;
      height: 100px;
    }
  </style>
</head>

<body>
  <div class="outer">
    <div class="center">
      <div class="inner">
        hello
      </div>
    </div>
  </div>
</body>
<script>
  var outer = document.getElementsByClassName('outer')[0];
  var center = document.getElementsByClassName('center')[0];
  var inner = document.getElementsByClassName('inner')[0];
  outer.onclick = function () {
    console.log("outer");
    event.stopPropagation(); // 阻止事件冒泡
  }
  center.onclick = function () {
    console.log("center");
    event.stopPropagation(); // 阻止事件冒泡
  }
  inner.onclick = function () {
    console.log("inner");
    // console.log(event);
    event.stopPropagation(); // 阻止事件冒泡
  }
</script>

</html>